<?php

class UserMSModel extends BaseModel
{
    protected $table = 'user_ms';

    const STATUS_NO_PASS = 1;   // 不通过
    const STATUS_PASS = 2;      // 通过

    const PRIVATE_RESERVE_STATUS_ONE = 1; // 允许查看详情状态
    const PRIVATE_RESERVE_STATUS_TWO = 2; // 允许详情页可预约状态

    /**
     * @param $uid
     * @return UserMSModel|null
     */
    public static function getPassedByUid($uid)
    {
        /** @var UserMSModel|null $return */
        $return  = self::query()
            ->where(['user_id' => $uid, 'status' => self::STATUS_PASS])
            ->orderBy('id', 'desc')
            ->first();
        return $return;
    }

    public function getRealFrontImgPath()
    {
        return getUploadDir() . $this->img_path_front;
    }

    public function getRealBackImgPath()
    {
        return getUploadDir() . $this->img_path_reverse;
    }

    public function getPhotoData()
    {
        $msArr = \MS\Minsh::getMsIdPhotoData($this->getRealFrontImgPath());//调取敏识数据
        $data = [
            'img_path_front' => $this->img_path_front,
            'img_path_reverse' => $this->img_path_reverse,
        ];
        $data['update_time'] = date('Y-m-d H:i:s', time());
        if (!empty($msArr['idNumber'])) {
            $data['card_id'] = empty($msArr['idNumber'])?'':$msArr['idNumber'];
            $data['address'] = empty($msArr['address'])?'':$msArr['address'];
            $data['birthday'] = empty($msArr['birthday'])?'':$msArr['birthday'];
            $data['name'] = empty($msArr['name'])?'':$msArr['name'];
            $data['people'] = empty($msArr['people'])?'':$msArr['people'];
            $data['sex'] = empty($msArr['sex'])?'':$msArr['sex'];
            $data['type'] = empty($msArr['type'])?'':$msArr['type'];
        }

        $msArr = \MS\Minsh::getMsIdPhotoData($this->getRealBackImgPath());//调取敏识数据
        $data['issueAuthority'] = empty($msArr['issueAuthority'])?'':$msArr['issueAuthority'];
        $data['validity'] = empty($msArr['validity'])?'':$msArr['validity'];

        if (empty($this->create_time)) {
            $data['create_time'] = date('Y-m-d H:i:s', time());
        }

        return $data;
    }

    public function isOK()
    {
        return $this->status == 2;
    }
}
